package com.ftg.shopping.sp_goodsinfo.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.shopping.config.LayuiPage;
import com.ftg.shopping.sp_goodsinfo.entity.sp_goodsinfo;
import com.ftg.shopping.sp_goodsinfo.mapper.GoodsMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class GoodsService {

    @Autowired
    GoodsMapper goodsMapper;

    public List<sp_goodsinfo> list(){ return goodsMapper.selectList(null); }

    public sp_goodsinfo findone(int id) {
        return goodsMapper.selectById(id);
    }

    public int insertgoods(sp_goodsinfo g){
        return goodsMapper.insertgoods(g);
    }

    public int updategoods(sp_goodsinfo g){ return goodsMapper.updateById(g); }

    public int deletegoods(int id){
        return  goodsMapper.deleteById(id);
    }

    public int deletegoodsIds(List<Integer> ids){
        return  goodsMapper.deleteBatchIds(ids);
    }


    public LayuiPage<sp_goodsinfo> testPage1(int page, int limit, String goodsname){
        IPage<sp_goodsinfo> ip = new Page<>(page,limit);
        QueryWrapper qw = new QueryWrapper();
        qw.like("goodsname",goodsname);
        goodsMapper.selectPage(ip,goodsname ==null || goodsname.equals("") ? null:qw);
        LayuiPage goods=new LayuiPage(ip);
        return goods;
    }

    public LayuiPage<sp_goodsinfo> get() {

        IPage<sp_goodsinfo> ip = new Page<>();

        LayuiPage goods = new LayuiPage(ip);
        goods.setCount(20);
        goods.setData(goodsMapper.get());
        return goods;
    }

    public LayuiPage<sp_goodsinfo> get1(String goodsname) {

        IPage<sp_goodsinfo> ip = new Page<>();

        LayuiPage goods = new LayuiPage(ip);
        goods.setCount(20);
        goods.setData(goodsMapper.get1(goodsname));
        return goods;
    }



    }



